import { db_set, db_get_int, db_set_obj, db_get_bool, db_get_float, db_get_str } from './base';

const g_state = () => db_get_str("state");              // state
const s_state = (v) => db_set("state", v);              // state

const g_gun = () => db_get_str("gun");                  // gun
const s_gun = (v) => db_set("gun", v);                  // gun

const g_psn = () => db_get_str("psn");                  // psn
const s_psn = (v) => db_set("psn", v);                  // psn

const g_model = () => db_get_str("model");              // model
const s_model = (v) => db_set("model", v);              // model

const g_wsn = () => db_get_str("wsn");                  // wsn
const s_wsn = (v) => db_set("wsn", v);                  // wsn

const g_line = () => db_get_str("line");                // line
const s_line = (v) => db_set("line", v);                // line

const g_db = {
    start_scan:     () =>      db_set("scan", false),
    stop_scan:      () =>      db_set("scan", true),
    is_stop_scan:   () => db_get_bool("scan"),
    tech:           () =>  db_get_str("tech"),
    s_tech:         (v) =>     db_set("tech", v),
    snum:           () =>  db_get_int("snum"),
    s_snum:         (v) =>     db_set("snum", v),
    anum:           () =>  db_get_int("anum"),
    s_anum:         (v) =>     db_set("anum", v),
    ng:             () =>  db_get_int("ng"),
    s_ng:           (v) =>     db_set("ng", v),
    ok:             () =>  db_get_int("ok"),
    s_ok:           (v) =>     db_set("ok", v),
    dnum:           () =>  db_get_int("dnum"),
    s_dnum:         (v) =>     db_set("dnum", v),
    out_w_tech:     () =>  db_get_float("out_w_tech"),
    s_out_w_tech:   (v) =>     db_set("out_w_tech", v),
    out_dia_tech:   () =>  db_get_float("out_dia_tech"),
    s_out_dia_tech: (v) =>     db_set("out_dia_tech", v),
    out_w_std:      () =>  db_get_float("out_w_std"),
    s_out_w_std:    (v) =>     db_set("out_w_std", v),
    out_dia_std:    () =>  db_get_float("out_dia_std"),
    s_out_dia_std:  (v) =>     db_set("out_dia_std", v),
    out_w_zero:    () =>  db_get_float("out_w_zero"),
    s_out_w_zero:  (v) =>     db_set("out_w_zero", v),
    out_dia_zero:  () =>  db_get_float("out_dia_zero"),
    s_out_dia_zero:(v) =>     db_set("out_dia_zero", v),
    out_w_up:      () =>  db_get_float("out_w_up"),
    s_out_w_up:(v) =>     db_set("out_w_up", v),
    out_dia_up:    () =>  db_get_float("out_dia_up"),
    s_out_dia_up:  (v) =>     db_set("out_dia_up", v),
    out_w_down:      () =>  db_get_float("out_w_down"),
    s_out_w_down:(v) =>     db_set("out_w_down", v),
    out_dia_down:    () =>  db_get_float("out_dia_down"),
    s_out_dia_down:  (v) =>     db_set("out_dia_down", v),
};

const clear_step = () => db_set_obj({
    state: "ready",
    num: 0,
    sum: 0,
    gun: "",
    psn: "",
});

export {g_db, g_wsn, g_state, g_gun, g_psn, g_model, g_line, clear_step, s_state, s_model, s_wsn, s_line, s_psn, s_gun};
